﻿using System;
using System.Collections.Generic;
using System.Text;
using Common.Xml;

namespace Common
{
    public class AppConfig
    {
        public static Encoding GetFileCodeType()
        {
            return Encoding.GetEncoding(System.Configuration.ConfigurationSettings.AppSettings["FileCode"].ToString());
        }
        public static string GetDBConnectionType()
        {
            return System.Configuration.ConfigurationSettings.AppSettings["DBType"].ToString();
        }

        //获取是否保存时更新文章
        public static bool GetEnabledSyncPageBySave()
        {
            bool result = false;
            XMLProcess objXMLProcess = new XMLProcess("Setting\\GlobalSet.config");
            string getConfig = objXMLProcess.ReadAttribute("/configuration/GlobalSet/SyncPageBySave", "Enable");
            if (getConfig.Trim().ToLower() == "true")
            {
                result = true;
            }
            return result;
        }

        //获取是否启用文件包含
        public static bool GetEnabledInculded()
        {
            bool result =false;
            XMLProcess objXMLProcess = new XMLProcess("Setting\\GlobalSet.config");
            string getConfig = objXMLProcess.ReadAttribute("/configuration/GlobalSet/PageType", "EnabledInclude");
            if (getConfig.Trim().ToLower() == "true")
            {
                result = true;
            }
            return result;
        }

        //获取栏目引用
        public static bool GetSectionReferEnabled()
        {
            bool result = false;
            XMLProcess objXMLProcess = new XMLProcess("Setting\\GlobalSet.config");
            string getConfig = objXMLProcess.ReadAttribute("/configuration/GlobalSet/SectionRefer", "Enable");
            if (getConfig.Trim().ToLower() == "true")
            {
                result = true;
            }
            return result;
        }

        //获取发布设置
        public static bool GetCommonIssue()
        {
            bool result =true;
            XMLProcess objXMLProcess = new XMLProcess("Setting\\GlobalSet.config");
            string getConfig = objXMLProcess.ReadAttribute("/configuration/GlobalSet/IssueType", "CommonIssue");
            if (getConfig.Trim().ToLower() == "false")
            {
                result = false;
            }
            return result;
        }

        //获取文章描述最大长度
        public static int GetArticleDescriptionMaxLength()
        {
            int result = 10000000;
            XMLProcess objXMLProcess = new XMLProcess("Setting\\GlobalSet.config");
            string getConfig = objXMLProcess.ReadAttribute("/configuration/GlobalSet/articleDescription", "MaxLength");
            int convertresult = 1;
            if (int.TryParse(getConfig.Trim(), out convertresult))
            {
                result = int.Parse(getConfig);
            }
            return result;
        }

        public static int GetIsChangeToHtml()
        {
            return int.Parse(System.Configuration.ConfigurationSettings.AppSettings["ChangeToHtml"].ToString());
        }

        public static int GetIshtml()
        {
            return int.Parse(System.Configuration.ConfigurationSettings.AppSettings["Ishtml"].ToString());
        }

        public static string GetSecctionIssuePages()
        {
            return System.Configuration.ConfigurationSettings.AppSettings["IssuePages"].ToString();
        }

        public static string GetWebFileType()
        {
            return System.Configuration.ConfigurationSettings.AppSettings["WebFileType"].ToString();
        }

        public static string GetServerUrl()
        {
            return System.Configuration.ConfigurationSettings.AppSettings["strUrl"].ToString();
        }
    }

}
